= render :partial => '/styles'
%h1 Error logs #{viewing_archive? ? '[archive]' : ''}

- form_tag({},:method => :get) do
  sort by: 
  = select_tag(:sort_by, options_for_select([['last error','last'],
    ['first error','first'],
    ['errors count','count'],
    ['level','level'],
    ['level then count','level_count']],
    session[:erlgs_sort_by]), :onchange => 'this.form.submit();' )

%div{:style => 'text-align: right'}
  - if viewing_archive?  
    = button_to "Delete all archived", :action => 'delete_all_archived' 
  - else
    = button_to "Mark all as read", :action => 'set_all_viewed' 
%br

-# Hell I love table layouts 
%table#error_logs_wrap
  %tr
    %td{:valign=>"top"}

      - all_count = @category_counts.values.sum
      %b Categories:
      %ul
        %li
          = link_to_if @opts[:category], 'all', :action => :index, :category => '-none-' 
          (#{all_count})
        - @category_counts.each_pair do |category,count| 
          %li
            #{link_to_if (@opts[:category] != category), category, :action => :index, :category => category}&nbsp;(#{count})

      - if @revisions.count > 1 
        %b Revisions:
        %ul
          %li
            = link_to_if @opts[:revision], 'all', :action => :index, :revision => '-none-' 
            (#{all_count})
          - @revisions.each do |rev| 
            %li{:style => 'white-space: nowrap'}
              - name = rev.created_at_first.to_date.to_s + '&nbsp;' 
              - name += (rev.vcs_revision.to_s.empty? ? 'unknown' : truncate(rev.vcs_revision,:length => 9))

              #{link_to_if (@opts[:revision] != rev.vcs_revision.to_s), raw(name), :action => :index, :revision => rev.vcs_revision.to_s}&nbsp;(#{rev.count_all})
      %br 
      %br 
      %br 
      - if viewing_archive? 
        = link_to 'view current', :archive => '0'
      - else
        = link_to 'view archive', :archive => '1'
    %td 
      %table#error_logs
        - @error_logs.each do |error_log| 
          = render :partial => '/error_log', :locals => {:error_log => error_log} 
